package com.ruoyi.buy.service.impl;

import com.ruoyi.buy.domain.entity.PO.BuyRequestbuyBillItem;
import com.ruoyi.buy.domain.entity.buy0010.Buy0010TableData;
import com.ruoyi.buy.domain.entity.buy0011.Buy0011TableData;
import com.ruoyi.buy.mapper.PO.BuyRequestbuyBillItemMapper;
import com.ruoyi.buy.mapper.PO.buy0010.Buy0010Mapper;
import com.ruoyi.buy.mapper.PO.buy0011.Buy0011Mapper;
import com.ruoyi.buy.service.IBuy0011Service;
import com.ruoyi.buy.service.ICommonService;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 参数配置 服务层实现
 * 
 * @author ruoyi
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class Buy0011ServiceImpl implements IBuy0011Service
{

    @Resource
    private Buy0011Mapper buy0011Mapper;

    @Resource
    Buy0010Mapper buy0010Mapper;

    @Resource
    BuyRequestbuyBillItemMapper buyRequestbuyBillItemMapper;



    @Autowired
    private ICommonService commonService;

    @Override
    public List<Buy0011TableData> getList(Buy0011TableData param) {
        return buy0011Mapper.getList(param);
    }

    @Override
    public List<Map<String, String>> getOprWithRole() {
        List<Buy0010TableData> list = this.buy0010Mapper.getList(new Buy0010TableData());
        List<Map<String, String>> result = new ArrayList();
        for (Buy0010TableData item:list
             ) {
            Map<String,String> map
                     =new HashMap<>();
            map.put("value", item.getvUserName());
            map.put("label", item.getvUserName()+ "-" +item.getvRoleName());
            result.add(map);
        }

        return result;
    }

    @Override
    public void save(Buy0011TableData para) {
        BuyRequestbuyBillItem buyRequestbuyBillItem = new BuyRequestbuyBillItem();
        BeanUtils.copyBeanProp(buyRequestbuyBillItem,para);
        buyRequestbuyBillItem.setUpdateBy(commonService.getUsername());
        buyRequestbuyBillItem.setUpdateTime(DateUtils.getNowDate());
        this.buyRequestbuyBillItemMapper.updateBuyRequestbuyBillItem(buyRequestbuyBillItem);
    }
}
